//
//  TaskTextView.m
//  Maintenance
//
//  Created by tox on 2017/9/17.
//  Copyright © 2017年 com.kaopudian. All rights reserved.
//

#import "TaskTextView.h"
@interface TaskTextView ()
@property (nonatomic, assign) CGSize size;
@end


@implementation TaskTextView

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        UILabel *label = [[UILabel alloc] init];
        [self addSubview:label];
        label.numberOfLines = 0;
        label.textColor = [UIColor colorWithHexString:@"999999"];
        self.placeholderLabel = label;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(placeholderLabelChange) name:UITextViewTextDidChangeNotification object:nil];
    }
    return self;
}



#pragma mark - 接收到通知消息后执行的方法
- (void)placeholderLabelChange
{
    self.placeholderLabel.hidden = self.text.length;
}

#pragma mark - 视图消失取消通知
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 计算提示Label的Frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    [self setUpFrame];
    
}
- (void)setUpFrame {
    self.placeholderLabel.frame = CGRectMake(5, 15, kSCREEN_WIDTH-115, 10);
}

#pragma mark - 重写提示属性的set方法
- (void)setPlaceholder:(NSString *)placeholder
{
    _placeholder = placeholder;
    [self setUpFrame];
    self.placeholderLabel.text = _placeholder;
    [self.placeholderLabel sizeToFit];
    self.placeholderLabel.hidden = self.text.length;
    
}

//- (void)setPlaceholderStr:(NSString *)placeholderStr{
//    _placeholderStr = placeholderStr;
//    
//    self.placeholderLabel.text = _placeholderStr;
//    self.placeholderLabel.hidden = self.text.length;
//}
@end
